Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--[BE][WIP] Remove Eigen dependency #2301

Draft
wants to merge 40 commits into
base: dev
Choose a base branch
from
Draft

--[BE][WIP] Remove Eigen dependency #2301

wants to merge 40 commits into from

Conversation

jturner65
Copy link
Contributor

@jturner65 jturner65 commented Jan 15, 2024

Motivation and Context

This PR removes Eigen library/dependency from Habitat-sim. It is intended to be an invisible change, and may require iterations to get everything.

Still a WIP.

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jan 15, 2024
@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 6 times, most recently from 78eee5f to 76938f1 Compare January 16, 2024 17:57
Copy link
Collaborator

@mosra mosra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hasty review while waiting for the CI.

You might want to clean up remains of Eigen in dependencies.cmake afterwards as well, including not enabling the EigenIntegration library anymore.

src/esp/core/Utility.h Outdated Show resolved Hide resolved
src/esp/geo/CoordinateFrame.h Outdated Show resolved Hide resolved
@@ -18,20 +20,21 @@ using Magnum::Math::Literals::operator""_rgb;
namespace esp {
namespace geo {

std::vector<vec2f> convexHull2D(const std::vector<vec2f>& points) {
std::vector<Mn::Vector2> convexHull2D(const std::vector<Mn::Vector2>& points) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could take a const array view while you're at it.

src/esp/geo/OBB.cpp Outdated Show resolved Hide resolved
src/esp/geo/OBB.h Outdated Show resolved Hide resolved
src/utils/datatool/Mp3dInstanceMeshData.cpp Outdated Show resolved Hide resolved
src/utils/datatool/Mp3dInstanceMeshData.h Outdated Show resolved Hide resolved
src/utils/datatool/Mp3dInstanceMeshData.cpp Outdated Show resolved Hide resolved
src/utils/datatool/Mp3dInstanceMeshData.h Outdated Show resolved Hide resolved
const Mn::Vector3 xyz_scene =
Mn::Vector3::from(&assimpMesh.mVertices[v].x);
const Mn::Vector3 xyz_esp =
alignSceneToEspGravity.transformVectorNormalized(xyz_scene);
mesh.vbo.push_back(xyz_esp);

if (assimpMesh.mNormals) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, there's a whole AssimpImporter for this kind of thing. Can't the datatool be just deleted or something?

A cleaner and safer way (bounds checking, type compatiblity checking...) instead of Mn::Vector3::from() etc would be to take the whole mNormals array, make an array view and cast it:

Cr::Containers::ArrayView<const Mn::Vector3> normals = 
    Cr::Containers::arrayCast<const Mn::Vector3>(Cr::Containers::arrayView(assimpMesh.mNormals, assimpMesh.mNumVertices));

And similar for positions etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know, I just don't want to make that decision unilaterally. @aclegg3 Thoughts?

@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 4 times, most recently from fdb649c to 3f6882e Compare January 22, 2024 21:14
// template <typename T>
// std::ostream& operator<<(std::ostream& os, const Map<T>& m) {
// return os << m.format(kJsonFormat);
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you plan here, but one way to efficiently format these might be with Utility::JsonWriter array support and vector.data() / matrix.data(), which both return a statically sized array reference.

Magnum::Math::cross(fromNorm, halfVec).normalized(),
Magnum::Math::dot(fromNorm, halfVec))
.normalized();
} // quatRotFromTwoVectors
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably too much to ask in this context, but I'd like to have this contributed to Magnum :)

src/esp/geo/CoordinateFrame.cpp Outdated Show resolved Hide resolved
src/esp/geo/CoordinateFrame.h Outdated Show resolved Hide resolved
@@ -988,7 +995,7 @@ struct NavMeshTileHeader {
};

struct Triangle {
std::vector<vec3f> v;
std::vector<Mn::Vector3> v;
Triangle() { v.resize(3); }
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow, ew, can't this be just a Mn::Vector3 v[3]? :D Or a Containers::StaticArray if you want bounds check in debug.

src/esp/sensor/Sensor.cpp Outdated Show resolved Hide resolved
src/tests/GeoTest.cpp Outdated Show resolved Hide resolved
auto v = agentBodyNode_->translation();
Cr::Utility::formatInto(res, res.length(),
"Agent position : [{} {} {}] ", v.x(), v.y(),
v.z());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessarily overcomplicated, just use the builtin debug output redirected to a stringstream. The redirection and if(res.size() > 0) is also redundant, if it's going to get printed it's non-empty already anyway.

ESP_DEBUG() << "Agent position:" << agentBodyNode_->translation();

Same below. If you want a more compact output for vectors (and quats), use Mn::Debug::packed << agentBodyNode_->translation() instead.

src/utils/viewer/viewer.cpp Outdated Show resolved Hide resolved
src/utils/viewer/viewer.cpp Outdated Show resolved Hide resolved
@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 2 times, most recently from 4aa0dff to 2f43fa1 Compare January 25, 2024 15:11
Comment on lines 958 to 968
const int numVerts = mesh.vbo.size();
const int numIndices = mesh.ibo.size();
const float mf = std::numeric_limits<float>::max();
vec3f bmin(mf, mf, mf);
vec3f bmax(-mf, -mf, -mf);
Mn::Vector3 bmin(mf, mf, mf);
Mn::Vector3 bmax(-mf, -mf, -mf);

for (int i = 0; i < numVerts; ++i) {
const vec3f& p = mesh.vbo[i];
bmin = bmin.cwiseMin(p);
bmax = bmax.cwiseMax(p);
const Mn::Vector3& p = mesh.vbo[i];
bmin = Mn::Math::min(bmin, p);
bmax = Mn::Math::max(bmax, p);
}
Copy link
Collaborator

@mosra mosra Jan 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was working on something unrelated and came across MeshTools::boundingRange(), which is basically just a call to Math::minmax(). No fancy SIMD internals there yet, but it's a candidate.

@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 3 times, most recently from afae3b5 to 1507e23 Compare February 5, 2024 13:58
@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 2 times, most recently from e382b1c to b371c7b Compare February 13, 2024 14:12
@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 2 times, most recently from 4d28775 to aef35d7 Compare February 21, 2024 14:32
@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 2 times, most recently from 7b25699 to f773e28 Compare February 29, 2024 17:05
@jturner65 jturner65 force-pushed the BE_RemoveEigenDeps branch 3 times, most recently from 49557ad to d58931c Compare March 5, 2024 20:02
magnum points can be directly compared
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants